<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>

<%@ page import="com.easyui.common.UserLogin" %>

<%
	String pno = request.getParameter("pno");
%>


<script type="text/javascript" charset="UTF-8">
	var discussDatagrid;
	$(function(){
		
		//我发布的帖子
		discussDatagrid = $('#discussDatagrid').datagrid({
			url:'../servlet/GetOwnDiscussServlet?pno=' + <%= pno %>,
			//title:'交流信息',
			//iconCls:'icon-save',
			fitColumns:true,
			nowrap:false,
			//striped:true,
			idField:'nno',
			pagination:true,
			pageSize:10,
			pageList:[10,20,30],
			fit:true,
			border:false,
			sortName:'nno',
			sortOrder:'desc',
			//showFooter:true,
			columns:[[{
				field:'nno',
				checkbox:true
			},{
				title:'标题',
				field:'ntitle',
				width:100,
				sortable:true,
				formatter: function(value,rowData,rowIndex){
		            return '<a href="discussDetail.jsp?nno=' + rowData.nno + '&page=1" target="_blank" style="text-decoration: none;">'+ value +'</a>';
		     	} 
			},{
				title:'发布者',
				field:'pubname',
				width:50
			},{
				title:'创建时间',
				field:'ptime',
				width:100,
				sortable:true
			},{
				title:'回复数',
				field:'replyNum',
				width:40
			},{
				title:'最后更新时间',
				field:'ltime',
				width:100,
				sortable:true
			}]],
			toolbar:[{
				text:'添加',
				iconCls:'icon-add',
				handler:function(){
					addHeadNote();
				}
			},'-',{
				text:'删除',
				iconCls:'icon-cancel',
				handler:function(){
					delHeadNote();
				}
			},'-',{
				text:'取消',
				iconCls:'icon-undo',
				handler:function(){
					discussDatagrid.datagrid('unselectAll');
					discussDatagrid.datagrid('rejectChanges');
				}
			},'-',{
				text:'刷新',
				iconCls:'icon-reload',
				handler:function(){
					discussDatagrid.datagrid('unselectAll');
					discussDatagrid.datagrid('rejectChanges');
					discussDatagrid.datagrid('load');
				}
			},'-']
		});
		
	});
	
	delHeadNote = function() {
		var rows = discussDatagrid.datagrid('getSelections');
		var ids = [];
		console.info(rows.length);
		if(rows.length > 0) {
			$.messager.confirm('提示','确定要删除所有选择的数据吗?',function(b) {
				if(b) {
					for(var i=0;i<rows.length; i++) {
						ids.push(rows[i].nno);
					}
					console.info(ids);
					$.ajax({
						url:'../servlet/DelHeadNoteServlet',
						data:{
							ids:ids.join(',')//用,分隔
						},
						type:'post',
						dataType:'json',
						success:function(r) {
							if(r && r.success) {
								discussDatagrid.datagrid('acceptChanges');
								discussDatagrid.datagrid('load');
								discussDatagrid.datagrid('unselectAll');
								discussDatagrid.datagrid('rejectChanges');
								//console.info(discussDatagrid.datagrid('getSelections'));
								$.messager.show({
									title:'提示',
									msg:'删除成功'
								});
							} else {
								$.messager.alert('出错啦','删除失败.','error');
							}
						}
					});
				}
			});
		} else {
			$.messager.alert('提示','未选择任何数据.','warning');
		}
	}
	
	addHeadNote = function() {
		addHeadNoteDialog = parent.$('#addHeadNoteDialog', parent.document).dialog({
			title:'发布新话题',
			modal:true,
			method:'post',
			collapsible:false,
			showHeader:false,
			width:700,
			height:550,
			href:'teacher/addHeadNote.jsp?pno=' + <%= pno %>
		});
		
		addHeadNoteDialog.dialog('open');
	}
	
	/* showDetailDiscuss = function(i) {
		var rows = discussDatagrid.datagrid('getRows');
		console.info(rows[i].nno);
	} */
	
</script>

<table id="discussDatagrid" fit="true"></table>
	
